package cn.ytr.project.web.listener;

import java.util.Date;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import cn.ytr.project.domain.AdminUser;
import cn.ytr.project.service.IAdminUserService;
import cn.ytr.project.service.impl.AdminUserServiceImpl;

public class InitAdminUserListener implements ServletContextListener{

	private IAdminUserService service = new AdminUserServiceImpl();
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		
		//数据库有没有 admin 用户，没有就自动创建一个
		AdminUser adminUser = service.selectByUsername("admin");
		if (adminUser == null) {
			service.insert(new AdminUser(null, "admin", new Date(), "123", null, null));
		}
		
	}

	
	
}
